<template>
  <div>
    <el-button type="primary" @click="shuffleCards">洗牌</el-button>
    <div class="card-container">
      <Card v-for="card in cards" :key="card.id" :card="card" @open-dialog="openDialog" />
    </div>
    <CardDialog v-model:visible="dialogVisible" :cardId="selectedCardId" />
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import { useStore } from 'vuex'
import Card from '../components/Card.vue'
import CardDialog from '../components/CardDialog.vue'

export default defineComponent({
  name: 'App',
  components: { Card, CardDialog },
  setup() {
    const store = useStore()

    const cards = computed(() => store.getters['cards/cards'])
    const dialogVisible = ref(false)
    const selectedCardId = ref(0)

    const shuffleCards = () => {
      store.dispatch('cards/shuffleCards')
    }

    const openDialog = (cardId: number) => {
      selectedCardId.value = cardId
      dialogVisible.value = true
    }

    return {
      cards,
      dialogVisible,
      selectedCardId,
      shuffleCards,
      openDialog,
    }
  },
})
</script>

<style>
.app {
  text-align: center;
  padding: 20px;
}

.card-container {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 20px;
}
</style>
